package org.karelun.gef.commands;

import java.util.List;

import org.eclipse.draw2d.geometry.Point;
import org.karelun.gef.model.AbstractConnectionModel;

public class MoveBendpointCommand extends AbstractCommand{

	private AbstractConnectionModel connection;
	
	private Point oldLocation,newLocation;
	
	private int index;
	
	public void execute(){
		List<Point> bendPoints = connection.getBendPoints();
		if(bendPoints==null||bendPoints.isEmpty())
			return;
		oldLocation= bendPoints.get(index);
		connection.replaceBendpoint(index, newLocation);
	}
	public void setConnection(Object model){
		this.connection=(AbstractConnectionModel)model;
	}
	public void setIndex(int i){
		this.index=i;
	}
	public void setNewLocation(Point newLoc){
		this.newLocation=newLoc;
	}
	public void undo(){
		connection.replaceBendpoint(index, oldLocation);
	}
	@Override
	public void redo() {
		execute();
	}
}
